package zhang.test.netfits_youmeng;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by Administrator on 2016/12/12.
 */

public class HomeActivity extends AppCompatActivity {
    private static final String TAG = "homeActivity";
    @BindView(R.id.bt_pay_product)
    Button btPayProduct;
    @BindView(R.id.bt_pay_product_draw)
    Button btPayProductDraw;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.bind(this);

//        UmengUpdateAgent.update(this);

        MobclickAgent.setDebugMode(true);

        // 场景类型设置接口
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);

        // 加密传输日志
        MobclickAgent.enableEncrypt(true);

        PushAgent.getInstance(getApplicationContext()).addAlias("15718852875", "PC", new UTrack.ICallBack() {
            @Override
            public void onMessage(boolean b, String s) {
                Log.d(TAG, "onMessage: b == " + b);
                Log.d(TAG, "onMessage: s == " + s);
            }
        });
    }

    @OnClick({R.id.bt_pay_product, R.id.bt_pay_product_draw, R.id.bt_data, R.id.bt_test01,
            R.id.bt_test02, R.id.bt_test03, R.id.bt_test04, R.id.bt_test05,
            R.id.bt_test06, R.id.bt_test07})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_pay_product: // 从home页面进入
                startActivity(new Intent(this, payItemActivity.class));
                Toast.makeText(this, "home", Toast.LENGTH_SHORT).show();
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("enter", "home");
//                MobclickAgent.onEvent(HomeActivity.this, "enter_pay", map);
                MobclickAgent.onEvent(HomeActivity.this, "enter_pay");
                break;

            case R.id.bt_pay_product_draw: // 从侧拉栏进入
                startActivity(new Intent(this, payItemActivity.class));
                HashMap<String, String> map2 = new HashMap<String, String>();
                map2.put("enter", "drawer");
//                MobclickAgent.onEvent(HomeActivity.this, "enter_pay", map2);
                MobclickAgent.onEvent(HomeActivity.this, "enter_pay");
                Toast.makeText(this, "drawer", Toast.LENGTH_SHORT).show();
                break;

            case R.id.bt_data:
                List eventlist1 = new ArrayList();
                eventlist1.add("pay");
                eventlist1.add("enter_pay");
                eventlist1.add("payItem");
                eventlist1.add("payMode");
                eventlist1.add("payResult");
                Toast.makeText(this, "data", Toast.LENGTH_SHORT).show();
                MobclickAgent.onEvent(this, eventlist1, eventlist1.size(), "pay");
                break;

            case R.id.bt_test01:
                Toast.makeText(this, "test01", Toast.LENGTH_SHORT).show();
                List list1 = new ArrayList();
                list1.add("test");
                list1.add("enter_pay");
                list1.add("payItem");
                list1.add("payMode");
                list1.add("payResult");
                MobclickAgent.onEvent(this, list1, list1.size(), "test");
                break;

            case R.id.bt_test02:
                List list2 = new ArrayList();
                list2.add("test02");
                list2.add("c");
                list2.add("d");
                Toast.makeText(this, "test02", Toast.LENGTH_SHORT).show();
                MobclickAgent.onEvent(this, list2, list2.size(), "test02");
                break;

            case R.id.bt_test03:
                List list3 = new ArrayList();
                list3.add("test03");
                list3.add("enter_pay");
                list3.add("payItem");
                list3.add("payMode");
                list3.add("payResult");
                Toast.makeText(this, "test03", Toast.LENGTH_SHORT).show();
                MobclickAgent.onEvent(this, list3, list3.size(), "test03");
                break;

            case R.id.bt_test04:
                List list4 = new ArrayList();
                list4.add("test04");
                list4.add("enter_pay");
                list4.add("payItem");
                list4.add("payMode");
                list4.add("payResult");
                Toast.makeText(this, "test04", Toast.LENGTH_SHORT).show();
                MobclickAgent.onEvent(this, list4, list4.size(), "test04");
                int a = 1 / 0;
                break;

            case R.id.bt_test05:
                Toast.makeText(this, "test05", Toast.LENGTH_SHORT).show();
                List list5 = new ArrayList();
                list5.add("test05");
                list5.add("enter_pay");
                list5.add("payItem");
                list5.add("payMode");
                list5.add("payResult");
                Toast.makeText(this, "test05", Toast.LENGTH_SHORT).show();
                MobclickAgent.onEvent(this, list5, list5.size(), "test05");

                int i = 1 / 0;
                break;

            case R.id.bt_test06:
                MobclickAgent.onProfileSignIn("7874395e");//用户账号ID

                //第一个参数为：账号来源。当用户使用第三方账号登录时可以这样统计
                MobclickAgent.onProfileSignIn("WB", "userID");
                Toast.makeText(this, "app", Toast.LENGTH_SHORT).show();
                break;

            case R.id.bt_test07:
                Toast.makeText(this, "退出", Toast.LENGTH_SHORT).show();
//                MobclickAgent.onProfileSignOff();
                HashMap<String, String> map3 = new HashMap<String, String>();
                map3.put("type","book");
                map3.put("item","条目一");
                map3.put("quantity","3");
                MobclickAgent.onEvent(this, "user", map3);
                break;
        }
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.bind(this).unbind();
    }
}
